﻿using System;
using System.IO;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace SVM_Sharp.Model
{
    /// <summary>
    /// Encapsulates an SVM Parameter.
    /// </summary>
    [Serializable]
    public class Parametros : IXmlSerializable
    {
        private static int m_sequence = 0;
        private double m_C;
        private double m_maxC;
        private double m_graoC;
        private double m_Gamma;
        private double m_maxGamma;
        private double m_graoGamma;
        private double m_Coef;
        private double m_maxCoef;
        private double m_graoCoef;
        private double m_pesoPositivo;
        private double m_pesoNegativo;
        private double m_maxDegree;
        private int m_id;
        private int m_Kernel;
        private int m_Degree;
        private int m_graoDegree;
        private bool m_multithread;
        private bool m_Scale;

        public XmlSchema GetSchema() { return null; }

        public void ReadXml(XmlReader reader)
        {
            bool t1 = reader.MoveToContent() == XmlNodeType.Element;
            bool t2 = reader.LocalName == "Parametro";
            if ( t1 && t2)
            {
                m_sequence = System.Convert.ToInt32(reader["sequence"]);
                m_C = System.Convert.ToDouble(reader["C"]);
                m_maxC = System.Convert.ToDouble(reader["maxC"]);
                m_graoC = System.Convert.ToDouble(reader["graoC"]);
                m_Gamma = System.Convert.ToDouble(reader["Gamma"]);
                m_maxGamma = System.Convert.ToDouble(reader["maxGamma"]);
                m_graoGamma = System.Convert.ToDouble(reader["graoGamma"]);
                m_Coef = System.Convert.ToDouble(reader["Coef"]);
                m_maxCoef = System.Convert.ToDouble(reader["maxCoef"]);
                m_graoCoef = System.Convert.ToDouble(reader["graoCoef"]);
                m_pesoPositivo = System.Convert.ToDouble(reader["pesoPositivo"]);
                m_pesoNegativo = System.Convert.ToDouble(reader["pesoNegativo"]);
                m_maxDegree = System.Convert.ToDouble(reader["maxDegree"]);

                m_id = System.Convert.ToInt32(reader["id"]);
                m_Kernel = System.Convert.ToInt32(reader["Kernel"]);
                m_Degree = System.Convert.ToInt32(reader["Degree"]);
                m_graoDegree = System.Convert.ToInt32(reader["graoDegree"]);

                m_multithread = System.Convert.ToBoolean(reader["multithread"]);
                m_Scale = System.Convert.ToBoolean(reader["Scale"]);

                reader.Read();
            }
        }

        public void WriteXml(XmlWriter writer)
        {
            writer.WriteAttributeString("sequence", m_sequence.ToString());
            writer.WriteAttributeString("C", m_C.ToString());
            writer.WriteAttributeString("maxC", m_maxC.ToString());
            writer.WriteAttributeString("graoC", m_graoC.ToString());
            writer.WriteAttributeString("Gamma", m_Gamma.ToString());
            writer.WriteAttributeString("maxGamma", m_maxGamma.ToString());
            writer.WriteAttributeString("graoGamma", m_graoGamma.ToString());
            writer.WriteAttributeString("Coef", m_Coef.ToString());
            writer.WriteAttributeString("maxCoef", m_maxCoef.ToString());
            writer.WriteAttributeString("graoCoef", m_graoCoef.ToString());
            writer.WriteAttributeString("pesoPositivo", m_pesoPositivo.ToString());
            writer.WriteAttributeString("pesoNegativo", m_pesoNegativo.ToString());
            writer.WriteAttributeString("maxDegree", m_maxDegree.ToString());

            writer.WriteAttributeString("id", m_id.ToString());
            writer.WriteAttributeString("Kernel", m_Kernel.ToString());
            writer.WriteAttributeString("Degree", m_Degree.ToString());
            writer.WriteAttributeString("graoDegree", m_graoDegree.ToString());

            writer.WriteAttributeString("multithread", m_multithread.ToString());
            writer.WriteAttributeString("Scale", m_Scale.ToString());
        }

        public Parametros()
        {
            this.setId(m_sequence++);
        }

        public Parametros(Parametros _parametros)
        {
            this.setId(m_sequence++);
            this.m_C = _parametros.getC();
            this.m_maxC = _parametros.getMaxC();
            this.m_graoC = _parametros.getGraoC();
            this.m_Scale = _parametros.getScale();
            this.m_pesoPositivo = _parametros.getPesoPositivo();
            this.m_pesoNegativo = _parametros.getPesoNegativo();
            this.m_Kernel = _parametros.getKernel();
            this.m_Gamma = _parametros.getGamma();
            this.m_maxGamma = _parametros.getMaxGamma();
            this.m_graoGamma = _parametros.getGraoGamma();
            this.m_Coef = _parametros.getCoef();
            this.m_maxCoef = _parametros.getMaxCoef();
            this.m_graoCoef = _parametros.getGraoCoef();
            this.m_Degree = _parametros.getDegree();
            this.m_maxDegree = _parametros.getMaxDegree();
            this.m_graoDegree = _parametros.getGraoDegree();
            this.m_multithread = _parametros.getMultithread();
        }

        public int getId()
        {
            return m_id;
        }

        public void setId(int _id)
        {
            m_id = _id;
        }

        public double getC()
        {
            return m_C;
        }

        public void setC(double _c)
        {
            m_C = _c;
        }

        public double getMaxC()
        {
            return m_maxC;
        }

        public void setMaxC(double _maxC)
        {
            m_maxC = _maxC;
        }

        public double getGraoC()
        {
            return m_graoC;
        }

        public void setGraoC(double _graoC)
        {
            m_graoC = _graoC;
        }

        public bool getScale()
        {
            return m_Scale;
        }

        public void setScale(bool _scale)
        {
            m_Scale = _scale;
        }

        public double getPesoPositivo()
        {
            return m_pesoPositivo;
        }

        public void setPesoPositivo(double _peso)
        {
            m_pesoPositivo = _peso;
        }

        public double getPesoNegativo()
        {
            return m_pesoNegativo;
        }

        public void setPesoNegativo(double _peso)
        {
            m_pesoNegativo = _peso;
        }

        public int getKernel()
        {
            return m_Kernel;
        }

        public void setKernel(int _kernel)
        {
            m_Kernel = _kernel;
        }

        public double getGamma()
        {
            return m_Gamma;
        }

        public void setGamma(double _gamma)
        {
            m_Gamma = _gamma;
        }

        public double getMaxGamma()
        {
            return m_maxGamma;
        }

        public void setMaxGamma(double _maxGamma)
        {
            m_maxGamma = _maxGamma;
        }

        public double getGraoGamma()
        {
            return m_graoGamma;
        }

        public void setGraoGamma(double _graoGamma)
        {
            m_graoGamma = _graoGamma;
        }

        public double getCoef()
        {
            return m_Coef;
        }

        public void setCoef(double _coef)
        {
            m_Coef = _coef;
        }

        public double getMaxCoef()
        {
            return m_maxCoef;
        }

        public void setMaxCoef(double _maxCoef)
        {
            m_maxCoef = _maxCoef;
        }

        public double getGraoCoef()
        {
            return m_graoCoef;
        }

        public void setGraoCoef(double _graoCoef)
        {
            m_graoCoef = _graoCoef;
        }

        public int getDegree()
        {
            return m_Degree;
        }

        public void setDegree(int _degree)
        {
            m_Degree = _degree;
        }

        public double getMaxDegree()
        {
            return m_maxDegree;
        }

        public void setMaxDegree(double _maxDegree)
        {
            m_maxDegree = _maxDegree;
        }

        public int getGraoDegree()
        {
            return m_graoDegree;
        }

        public void setGraoDegree(int _graoDegree)
        {
            m_graoDegree = _graoDegree;
        }

        public bool getMultithread()
        {
            return m_multithread;
        }

        public void setMultithread(bool val)
        {
            m_multithread = val;
        }
    }
}